#ifndef XGE_XLOG_MESSAGE_H_
#define XGE_XLOG_MESSAGE_H_
#include "xge_common_config.h"
#include "xcommon_task.h"

namespace xge{
namespace xge_internal{
    
  // A XLogMessage basically has 2 work phase
  // 1. Format the target the string into the buffer
  // 2. Flush the buffer into the file 
  // We should do the formating stuff in the callee since the
  // va_list is on the stack we can not just copy it or something like this
  // But the flush operation can assign to the back thread in order to
  // save the time.
  // This is a internal class which use by the export function 

  class XLogMessage {
  public:
    // Creating a XLogMessage using the format pair
    XLogMessage(
      LogLevel level ,  
      const char_t* file,
      const char_t* func,
      int line,
      const char_t* format , 
      va_list var_list
      );
    ~XLogMessage();
  public:
    // Flush this information directly 
    void Flush( bool here = true ) {
      LocalFlush(true);
    }
    // Remote this information to the back thread
    XLogMessage& Remote() {
      remote_ = true;
      return *this;
    }
    // Ignore time information 
    // ONLY this time
    XLogMessage& IgnoreTimeInformation() {
      time_ = false;
    }
    // Link this information to some other information level
    XLogMessage& Link( LogLevel level ) {
      level_ |= level;
    }
    // Sink this information to the specific target level
    XLogMessage& SinkUntil ( LogLevel level );
  private:
    void LocalFlush( bool really = false );
    char_t message_buf_[ MAX_CHAR_STACK_BUFFER_SIZE ];
    bool remote_;
    bool time_;
    LogLevel level_;
  };


}//namespace xge_internal
}//namespace xge

#endif// XGE_LOG_MESSAGE_H_